package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.mapper.HdidRelationMapper;
import cn.jiahua.hospital.pojo.HdidRelation;
import cn.jiahua.hospital.service.HdidRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

@Service
public class HdidRelationServiceImpl implements HdidRelationService {

    @Autowired
    private HdidRelationMapper hdidRelationMapper;

    @Override
    public HdidRelation getHdidRelationById(Integer id) {
        return hdidRelationMapper.getHdidRelationById(id);
    }

    @Override
    public List<HdidRelation> getHdidRelationListByMap(Map<String, Object> param) {
        return hdidRelationMapper.getHdidRelationListByMap(param);
    }

    @Override
    public Integer getHdidRelationCountByMap(Map<String, Object> param) {
        return hdidRelationMapper.getHdidRelationCountByMap(param);
    }

    @Override
    public Integer qdtxAddHdidRelation(HdidRelation hdidRelation) {
        return hdidRelationMapper.insertHdidRelation(hdidRelation);
    }

    @Override
    public Integer qdtxModifyHdidRelation(HdidRelation hdidRelation) {
        return hdidRelationMapper.updateHdidRelation(hdidRelation);
    }

    @Override
    public Integer qdtxDeleteHdidRelationById(Integer id) {
        return hdidRelationMapper.deleteHdidRelationById(id);
    }

    @Override
    public Integer qdtxBatchDeleteHdidRelation(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return hdidRelationMapper.batchDeleteHdidRelation(param);
    }

    @Override
    public Page<HdidRelation> queryHdidRelationPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = hdidRelationMapper.getHdidRelationCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<HdidRelation> hdidRelationList = hdidRelationMapper.getHdidRelationListByMap(param);
        page.setList(hdidRelationList);
        return page;
    }

    @Override
    public Integer modify(HdidRelation hdidRelation) {
        return hdidRelationMapper.modify(hdidRelation);
    }

    @Override
    public Integer modifyDoctor(HdidRelation hdidRelation) {
        return hdidRelationMapper.modifyDoctor(hdidRelation);
    }

    @Override
    public List<HdidRelation> selectDT(Integer hospitalId, String tdepartmentsName, String name) {
        return hdidRelationMapper.selectDT(hospitalId,tdepartmentsName,name);
    }
}